package com.example.diaoxinlei

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.example.diaoxinlei.ui.theme.Student

class StudentAdapter(private val students: List<Student>) : RecyclerView.Adapter<StudentAdapter.StudentViewHolder>() {

    class StudentViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
        val idTextView: TextView = itemView.findViewById(R.id.student_id)
        val nameTextView: TextView = itemView.findViewById(R.id.student_name)
        val genderTextView: TextView = itemView.findViewById(R.id.student_gender)
        val classTextView: TextView = itemView.findViewById(R.id.student_class)
    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): StudentViewHolder {
        val view = LayoutInflater.from(parent.context).inflate(R.layout.activity_student_adapter, parent, false)
        return StudentViewHolder(view)
    }

    override fun onBindViewHolder(holder: StudentViewHolder, position: Int) {
        val student = students[position]
        holder.idTextView.text = student.id
        holder.nameTextView.text = student.name
        holder.genderTextView.text = student.gender
        holder.classTextView.text = student.className
    }

    override fun getItemCount(): Int {
        return students.size
    }
}